//
//  CommonUtil.m
//  Kjs-iOS
//
//  Created by 江伟 on 16/7/23.
//  Copyright © 2016年 jmhz. All rights reserved.
//

#import "CommonUtil.h"

@implementation CommonUtil

+ (NSString *)getItemStatusStrWithStatus:(int)itemStatus{
    NSString *itemStatusStr = [[NSString alloc] init];
    switch (itemStatus) {
        case -1:
            itemStatusStr = @"重新提交";
            break;
        case 0:
            itemStatusStr = @"未提交";
            break;
        case 1:
            itemStatusStr = @"待审核";
            break;
        case 2:
            itemStatusStr = @"资料待补充";
            break;
        case 3:
            itemStatusStr = @"待美工";
            break;
        case 4:
            itemStatusStr = @"待发送";
            break;
        case 5:
            itemStatusStr = @"待确认上线";
            break;
        case 6:
            itemStatusStr = @"上线失败";
            break;
        case 7:
            itemStatusStr = @"募集中";
            break;
        case 8:
            itemStatusStr = @"预热中";
            break;
        case 9:
            itemStatusStr = @"募集成功";
            break;
        case 10:
            itemStatusStr = @"募集终止";
            break;
        case 100:
            itemStatusStr = @"已退回";
            break;
        case 200:
            itemStatusStr = @"待退回";
        default:
            break;
    };
    return itemStatusStr;
}

+ (NSString *)getGdBenefitModeStrWithMode:(int)gdBenefitMode{
    NSString *modeStr = [[NSString alloc] init];
    switch (gdBenefitMode) {
        case Month:
            modeStr = @"按月付息到期还本";
            break;
        case Once:
            modeStr = @"到期一次性还本付息";
        default:
            break;
    }
    return modeStr;
}

+ (NSString *)getGdBenefitModeStrWithStrMode:(NSString *)gdBenefitMode{
    NSString *modeStr = [[NSString alloc] init];
    if ([gdBenefitMode isEqualToString:@"0"]) {
        modeStr = @"到期一次性还本付息";
    } else if ([gdBenefitMode isEqualToString:@"1"]) {
        modeStr = @"按月付息到期还本";
    }
    return modeStr;
}

+ (NSString *)getOrderStatusStrWithMode:(NSString *)orderStatus{
    NSString *statusStr =[[NSString alloc] init];
    if ([orderStatus isEqualToString:@"closed"]) {
        statusStr = @"订单关闭";
    } else if ([orderStatus isEqualToString:@"cancelled"]) {
        statusStr = @"订单取消";
    } else if ([orderStatus isEqualToString:@"unpaid"]) {
        statusStr = @"未支付";
    } else if ([orderStatus isEqualToString:@"paid"]) {
        statusStr = @"已支付";
    } else if ([orderStatus isEqualToString:@"needvoucher"]) {
        statusStr = @"待提供支付凭证";
    } else if ([orderStatus isEqualToString:@"unconfirmed"]) {
        statusStr = @"待确认";
    } else if ([orderStatus isEqualToString:@"invalid"]) {
        statusStr = @"订单失效";
    }
    return statusStr;
}

+ (NSString *)getLogTypeNameWithTpye:(NSString *)type{
    NSString *typeName = [[NSString alloc] init];
    if ([type isEqualToString:@"chongzhi"]) {
        typeName = @"充值";
    } else if ([type isEqualToString:@"tixianchenggong"]) {
        typeName = @"提现成功";
    } else if ([type isEqualToString:@"tixiandongjie"]) {
        typeName = @"提现冻结";
    } else if ([type isEqualToString:@"zqrzbenjinfanhuan"]) {
        typeName = @"本金返还";
    } else if ([type isEqualToString:@"zqrzchoukuanhuabo"]) {
        typeName = @"筹款划拨";
    } else if ([type isEqualToString:@"zqrzzhifulixi"]) {
        typeName = @"支付利息";
    } else if ([type isEqualToString:@"zqrzchenggong"]) {
        typeName = @"募集成功";
    }else if ([type isEqualToString:@"zqtzchenggong"]) {
        typeName = @"投资成功";
    }else if ([type isEqualToString:@"zqtzdongjie"]) {
        typeName = @"投资冻结";
    }else if ([type isEqualToString:@"zqtzbenjinshouhui"]) {
        typeName = @"本金收回";
    }else if ([type isEqualToString:@"zqtzshouhuilixi"]) {
        typeName = @"收回利息";
    }else if ([type isEqualToString:@"zqtztuihui"]) {
        typeName = @"募集终止退回";
    }
    return typeName;
    
}

+ (NSString *)getOrderPayModeNameWithMode:(NSString *)mode{
    NSString *payModeName = [[NSString alloc] init];
    if ([mode isEqualToString:@"yuezifu"]) {
        payModeName = @"余额支付";
    } else if ([mode isEqualToString:@"wangyinzhifu"]) {
        payModeName = @"网银支付";
    } else if ([mode isEqualToString:@"xianxiazhifu"]) {
        payModeName = @"线下支付";
    }
    return payModeName;
}

+ (NSInteger)getColorByBankType:(NSInteger)type{
    NSInteger color;
    if (type == haixia || type == jianshe || type == jiaotong || type == minsheng || type == pufa || type == quanzhou || type == xiamen || type == xiamenguoji || type == xingye) {
        color = blue;
    }else if (type == gongshang || type == guangfa || type == huaxia || type == huifeng || type == pingan || type == hengsheng || type == zhaoshang || type == zhongguo || type == zhongxin){
        color = red;
    }else{
        color = blue;
    }
    return color;
}
+ (BOOL) validateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}
+ (BOOL)validateMobile:(NSString *)mobile
{
    NSString *MOBILE = @"^1[34578]\\d{9}$";
    NSPredicate *regexTestMobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE];
    return [regexTestMobile evaluateWithObject:mobile];
}
+ (BOOL) validatePassword:(NSString *)passWord
{
    NSString *passWordRegex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:passWord];
}
+ (BOOL) validateName:(NSString *)name
{
    NSString *nameRegex = @"^[\u4E00-\u9FA5]+$";
    NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nameRegex];
    return [namePredicate evaluateWithObject:name];
}
+ (BOOL) validateIdentityCard: (NSString *)identityCard
{
    NSString *pattern = @"(^[0-9]{15}$)|([0-9]{17}([0-9]|X)$)";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:identityCard];
    return isMatch;
}
+ (BOOL) validateTradePsw:(NSString *)tradePsw
{
    if ([tradePsw length] >=6 && [tradePsw length] <=16){
        return YES;
    }else
        return NO;
}
+ (NSString *)subZeorFrom:(NSString *)number
{
    //去掉小数点后多余的0
    NSString * s = nil;
    NSInteger offset = number.length - 2;
    while (offset)
    {
        s = [number substringWithRange:NSMakeRange(offset, 1)];
        if ([s isEqualToString:@"0"] || [s isEqualToString:@"."])
        {
            offset--;
        }
        else
        {
            break;
        }
    }
    return  [number substringToIndex:offset+1];
}
@end
